Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

fix(wireprotocol): only send bypassDocumentValidation if true #317

Merged
merged 3 commits into from
Jun 14, 2018

Conversation

shsaskin
Copy link

The bypassDocumentValidation key will only be set if it explicitly
receives a true, otherwise it remains undefined.

Fixes NODE-1492

The bypassDocumentValidation key will only be set if it explicitly
receives a true, otherwise it remains undefined.

Fixes NODE-1492
Copy link
Contributor

@kvwalker kvwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

Copy link
Contributor

@daprahamian daprahamian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

Copy link
Member

@mbroadst mbroadst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job! just a few comments

const wireProtocol2_6 = require('../../../lib/wireprotocol/2_6_support.js');
const wireProtocol3_2 = require('../../../lib/wireprotocol/3_2_support.js');

const MockPool = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we actually make this a class MockPool { write() { ... } } so we can potentially reuse it for other purposes in the future?


describe('WireProtocol', function() {
it('2.6 should only set bypassDocumentValidation to true if explicitly set by user to true', function(done) {
const options = { bypassDocumentValidation: true };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you would create a const pool = new MockPool( /* maybe future options */ ) and pass that into the insert method.

describe('WireProtocol', function() {
it('2.6 should only set bypassDocumentValidation to true if explicitly set by user to true', function(done) {
const options = { bypassDocumentValidation: true };
wireProtocol2_6.prototype.insert(MockPool, '', '', bson, 'ops', options, function(err, data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly I would recommend creating an instance of the WireProtocol: const wireProtocol = new WireProtocol2_6(); and using wireProtocol.insert

describe('WireProtocol', function() {
it('2.6 should only set bypassDocumentValidation to true if explicitly set by user to true', function(done) {
const options = { bypassDocumentValidation: true };
wireProtocol2_6.prototype.insert(MockPool, '', '', bson, 'ops', options, function(err, data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally, I think for readability-sake in the future it would be best to name the variables you are passing in fake data for, e.g.

const ns = 'fake.namespace';
const ismaster = {};
...

wireProtocol.insert(pool, ns, ismaster, ...)

Copy link
Member

@mbroadst mbroadst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@daprahamian daprahamian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are currently reusing fake_bson, fake_topology, and pool across all the tests. This is not advisable, as spies maintain state. You should do one of the following:

  1. Move the creation of the mocks to within testPoolWrite
  2. Create a beforeEach hook that creates a new fake_bson, fake_topology, and pool for each test.

MockPool.write = function(cmd, options, callback) {
callback(null, cmd);
const fake_topology = 'fake_topology';
const fake_bson = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably replace this with sinon.createStubInstance(bson).

};

const pool = new Pool(fake_topology, { bson: fake_bson });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two lines could be const pool = sinon.createStubInstance(Pool)

function testPoolWrite(bypassDocumentValidation, wireProtocol, expected) {
const isMaster = {};
const ns = 'fake.namespace';
const ops = 'fake.ops';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops should be an array of operations. Ideally, you would do something like:

const ops = [ {a: 1}, {b: 2} ];


MockPool.write = function(cmd, options, callback) {
callback(null, cmd);
const fake_topology = 'fake_topology';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The topology is normally an object. I don't think it is worth it to stub the whole topology, but it should probably be an empty object {} instead of a string.

@shsaskin shsaskin merged commit a81678b into master Jun 14, 2018
@shsaskin shsaskin deleted the NODE-1492-bypassDocumentValidation branch June 14, 2018 17:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants